<?php
  include_once $_SERVER['DOCUMENT_ROOT'].'/PariGest/pages/inc/entete.php';
  require_once $REP_CLASS . 'class.Pari.php';
  require_once $REP_CLASS . 'class.Operation.php';
  require_once $REP_CLASS . 'class.Parametrage.php';
  
  include $REP_PAGES . 'IncSelectCompte.php';
  
  try
  {
    $pari = new Pari($db);
    $parametrage = new Parametrage($db);
    
    $parametrage->setIdCompte(getChaineNotNullSinon("idCompte", ""));
    $parametrage->affichage();
    
    /*$stmt = $pari->selectParisEncours($idCompte);*/
    $trace->fb('LstSports : ' . getChaineNotNullSinon("LstSports", "null"));
    if( $action == 'UPDATE' )
    {
      $IndSportSession = getChaineNotNullSinon("LstSports", Pari::$IND_SPORT_FOOT);
      setcookie(Pari::$IND_SPORT_SESSION, $IndSportSession, time()+360000);
      
      $Cote = getChaineNotNullSinon("Cote", "");
      setcookie(Pari::$COTE_SESSION, $Cote, time()+360000);
      
      $pari->setCote(getChaineNotNullSinon("Cote", ""));
      $pari->setDate(convMajDate(getChaineNotNullSinon("Date", "")));
      $pari->setIdCompte(getChaineNotNullSinon("idCompte", ""));
      $pari->setIndCombine(getChaineNotNullSinon("IndCombine", ""));
      //$pari->setIndResultat(getChaineNotNullSinon("LstSports", ""));
      $pari->setIndSport(getChaineNotNullSinon("LstSports", ""));
      $pari->setMise(getChaineNotNullSinon("Mise", ""));
      $pari->setNbPari(getChaineNotNullSinon("NbParis", ""));
      $pari->insertion();
    }
    else
    {
      if( isset($_COOKIE[Pari::$IND_SPORT_SESSION]) )
      {
        $IndSportSession = $_COOKIE[Pari::$IND_SPORT_SESSION];
      }
      else
      {
        $IndSportSession = Pari::$IND_SPORT_FOOT;
        setcookie(Pari::$IND_SPORT_SESSION, $IndSportSession, time()+360000);
      }
      
      if( isset($_COOKIE[Pari::$COTE_SESSION]) )
      {
        $Cote = $_COOKIE[Pari::$COTE_SESSION];
      }
      else
      {
        $Cote = "";
        setcookie(Pari::$COTE_SESSION, $Cote, time()+360000);
      }
    }
    
    $trace->fb('Avant le commit');
    $db->commit();
    $trace->fb('Apres le commit');
  }
  catch(MyException $e)
  {
    $trace->fb('!!!!! ERREUR !!!!!');
    include $_SERVER['DOCUMENT_ROOT'].'/PariGest/pages/inc/catch.php';
  }
  $smarty->assign('REP_PAGES', $REP_PAGES);
  $smarty->assign('LstSports', Pari::selectAllSports());
  $smarty->assign('IndSportSelected', $IndSportSession);
  $smarty->assign('CoteDefaut', $Cote == ""?"Cote":$Cote);
  $smarty->assign('DateDuJour', getDateToday());
  $smarty->assign('MiseMini', $parametrage->getMiseMini());
  $smarty->display('jeux.tpl');
?>
